﻿using MahApps.Metro.Controls.Dialogs;
using System.Windows;
using System.Windows.Controls;
using VideoTools.Commands;
using VideoTools.vo;

namespace VideoTools.VideoView
{
    /// <summary>
    /// ConfigEs.xaml 的交互逻辑
    /// </summary>
    public partial class DownloadM3u8SettingWindow : System.Windows.Controls.UserControl
    {
        private static volatile DownloadM3u8SettingWindow _instance;
        private static object _syncRoot = new object();
        
        public static DownloadM3u8SettingWindow Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_syncRoot)
                    {
                        if (_instance == null)
                        {
                            _instance = new DownloadM3u8SettingWindow();
                        }

                    }
                }
                return _instance;
            }
        }

        public DownloadM3u8SettingWindow()
        {
            InitializeComponent();
            this.DataContext = DownloadM3u8Commands.Instance;
        }

        private void M3u8_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (mCombox.SelectedItem is M3u8 selectedConfig)
            {
                DownloadM3u8Commands.Instance.SelectedConfig = selectedConfig;
                mDomain.Text = selectedConfig.domain;
                mTitleReg.Text = selectedConfig.titleReg;
                mUrlReg.Text = selectedConfig.urlReg;
                mM3u8UrlReg.Text = selectedConfig?.m3u8UrlReg;
                mStart.SelectedItem = selectedConfig?.start;
            }
        }

        private void MaxConcurrentDownloadCount_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            //DownloadM3u8Commands.Instance.TaskManager.MaxConcurrentTasks = (int)e.NewValue;
            DownloadM3u8Commands.Instance.TaskManager.MaxConcurrentTasks = (int)e.NewValue;
        }

    }
}
